<?php
/**
 * Created by PhpStorm.
 * User:王加明
 * Date: 2017-04-13
 * Time: 下午 1:40
 */
namespace app\hongyanche\model;
use think\Db;
class Maintain_api extends Maintain{
    //被动接收车辆实销数据
    protected function car_sale(){
        $data = input();
        $data = json_decode($data['data'],1);
        try {
            $res = Db::name('maintain_zvehicle')->insertAll($data);
        }catch (\Exception $e){
            return array('state'=>0,'errormsg'=>'Parameter error');
        }
        if($res) {
            return [
                'state' => 1,
                'errormsg' => 'Receive success'
            ];
        }
        return [
            'state' => 0,
            'errormsg' => 'Receive false'
        ];
    }
    //被动获取服务信息详情接口
    protected function receive_information(){
        $data = $_REQUEST;
        if($data){
            return $data;
        }else{
            return;
        }
    }

    //获取服务站信息
   function getServiceInfo(){
        $data = $_POST;
        if($data){
            return $data;
        }else{
            return;
        }
    }
    //获取车联网返回申请信息接口
    protected function refound(){

    }
    //向车联网推送数据
    function send($url,$type="get",$res="json",$arr=""){
        // 获取imoc
        // 1 初始化curl
        $ch = curl_init($url);
        // 2 设置参数
        curl_setopt($ch,CURLOPT_URL,$url); //设置url
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        if($type == "post"){
            curl_setopt($ch,CURLOPT_POST,true);
            curl_setopt($ch,CURLOPT_POSTFIELDS,$arr);	//参数内容
        }
        //3.采集
        $output = curl_exec($ch);
        if($res == "json"){
            if(curl_errno($ch)){
                return curl_errno($ch);
            }else{
                return json_decode($output,true);
            }

        }
        //4.关闭
        curl_close($ch);
    }

}